package cn.stylefeng.guns.modular.business.frequency.orderabnormal.controller;

import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.modular.business.frequency.orderabnormal.model.param.OrderAbnormalDTO;
import cn.stylefeng.guns.modular.business.frequency.orderabnormal.service.OrderAbnormalService;
import cn.stylefeng.guns.modular.business.util.BusinessUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author jzy
 * @Date 2021/5/26 0026
 **/
@Api(tags = "异常订单")
@RestController
@RequestMapping("/api/order-abnormal")
public class OrderAbnormalController {

    @Resource
    private OrderAbnormalService orderAbnormalService;
    @Autowired
    private BusinessUtil businessUtil;

    @ApiOperation(value = "异常订单待处理列表")
    @GetMapping("/wait")
    public ResponseData getWaitList(OrderAbnormalDTO orderAbnormalDTO) {
        // 排序
        if (StringUtils.isBlank(orderAbnormalDTO.getColumn())) {
            orderAbnormalDTO.setColumn("os.id");
        }
        // 数据范围
        List<Long> empByOrgList = businessUtil.getEmpByOrgList();

        orderAbnormalDTO.setDataList(empByOrgList);
        return orderAbnormalService.getWaitList( orderAbnormalDTO);
    }

    @ApiOperation(value = "异常订单已解除分页列表")
    @GetMapping("/relieve/page")
    public ResponseData getRelieveList( OrderAbnormalDTO orderAbnormalDTO) {
        // 排序
        if (StringUtils.isBlank(orderAbnormalDTO.getColumn())) {
            orderAbnormalDTO.setColumn("os.id");
        }
        orderAbnormalDTO.setStatus(1);
        List<Long> empByOrgList = businessUtil.getEmpByOrgList();
        orderAbnormalDTO.setDataList(empByOrgList);
        return  orderAbnormalService.getRelieveListPage(orderAbnormalDTO);
    }



    @ApiOperation(value = "更改是否处罚状态")
    @PutMapping("/punish/{id}")
    public ResponseData updatePunish(@PathVariable String id) {
        orderAbnormalService.updatePunishStatus(id);
        return ResponseData.success();
    }

    @ApiOperation(value = "异常解除")
    @PutMapping("/relieve/{id}")
    public ResponseData relieve(@PathVariable String id) {
        orderAbnormalService.relieve(id);
        return new ResponseData();
    }

}
